﻿using Microsoft.Xna.Framework;
using Phoenix.Xna.Framework.Input;
using Phoenix.Xna.Framework.Input.Mice;
using Phoenix.Xna.Framework.Input.Keyboards;

namespace Phoenix.Xna.Framework.Components.Cameras
{
    public class FreeCamera : Camera
    {
        public FreeCamera()
            : base()
        {
        }

        public FreeCamera(string id)
            : base(id)
        {
        }

        public FreeCamera(string id, float fov, float nearClip, float farClip)
            : base(id, fov, nearClip, farClip)
        {
        }

        protected virtual void OnAxisChanged(object sender, InputMapEventArgs<MouseAxisMap> e)
        {
            EulerRotation = new Vector3(EulerRotation.X - (RotationDelta * e.InputMap.CurrentPositionDelta.X),
                EulerRotation.Y - (RotationDelta * e.InputMap.CurrentPositionDelta.Y),
                EulerRotation.Z);
        }

        protected virtual void OnMoveLeft(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveLeft();
        }

        protected virtual void OnMoveRight(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveRight();
        }

        protected virtual void OnMoveForward(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveForward();
        }

        protected virtual void OnMoveBackward(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveBackward();
        }

        protected virtual void OnMoveUp(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveUp();
        }

        protected virtual void OnMoveDown(object sender, InputMapEventArgs<KeyboardKeyMap> e)
        {
            MoveDown();
        }

        #region Camera Members

        public override void Initialize()
        {
            RotationDelta = 0.005f;

            if (MoveDelta == 0)
            {
                MoveDelta = 10f;
            }

            base.Initialize();
        }

        #endregion
    }
}
